home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode Previous / Geometry Samples- Mac / GeometryTest / Textures.c < prev    next >
Encoding:
Text File  |  1999-05-18  |  3.6 KB  |  131 lines  |  [TEXT/MPCC]

  1. // routines to allow us to put texture maps on a parameterized group
  2.  
  3. #include <QuickDraw.h>
  4. #include "QD3D.h"
  5. #include "QD3DGroup.h"
  6. #include "QD3DShader.h"
  7.  
  8.  
  9. #include "PictRead.h"        // this is a library file from QD3D applications folder
  10. #include "Textures.h"
  11.  
  12. TQ3Status AddTextureToGroup( TQ3GroupObject    theGroup, TQ3StoragePixmap *textureImage)
  13. {
  14.     TQ3TextureObject    textureObject;
  15.     TQ3GroupPosition    position;
  16.     TQ3Object            firstObject;
  17.     TQ3ShaderObject     textureShader;
  18.  
  19.     textureObject = Q3PixmapTexture_New(textureImage);
  20.     
  21.     if( textureObject ) {
  22.         if( Q3Object_IsType(theGroup, kQ3GroupTypeDisplay) == kQ3True) {
  23.             Q3Group_GetFirstPosition(theGroup, &position);
  24.     
  25.             Q3Group_GetPositionObject(theGroup, position,    &firstObject);
  26.     
  27.             if( Q3Object_IsType(firstObject, kQ3SurfaceShaderTypeTexture) == kQ3True) {
  28.                 TQ3TextureObject    oldTextureObject;
  29.                 TQ3StoragePixmap oldTextureImage;
  30.                         
  31.                 Q3TextureShader_GetTexture(firstObject, &oldTextureObject);
  32.                 Q3PixmapTexture_GetPixmap(oldTextureObject, &oldTextureImage);
  33.                 
  34.                 Q3Object_Dispose(oldTextureObject);
  35.                 Q3TextureShader_SetTexture(firstObject, textureObject);
  36.                 Q3Object_Dispose(textureObject);
  37.             } else {
  38.                 textureShader = Q3TextureShader_New(textureObject);
  39.                 Q3Object_Dispose(textureObject);
  40.                 //Q3Group_SetPositionObject(theGroup, position, theDocument->textureShader);
  41.                 Q3Group_AddObjectBefore(theGroup, position, textureShader);
  42.                 Q3Object_Dispose(textureShader);
  43.             }
  44.             
  45.             Q3Object_Dispose(firstObject);
  46.         } else if( Q3Object_IsType(theGroup, kQ3DisplayGroupTypeOrdered) == kQ3True) {            
  47.             Q3Group_GetFirstPositionOfType(
  48.                 theGroup,
  49.                 kQ3ShapeTypeShader, &position);    
  50.             
  51.             if( position ) {
  52.                 Q3Group_GetPositionObject(theGroup, position,    &firstObject);
  53.     
  54.                 if( Q3Object_IsType(firstObject, kQ3SurfaceShaderTypeTexture) == kQ3True) {
  55.                     TQ3TextureObject    oldTextureObject;
  56.                     TQ3StoragePixmap oldTextureImage;
  57.                     
  58.                     Q3TextureShader_GetTexture(firstObject, &oldTextureObject);
  59.                     Q3PixmapTexture_GetPixmap(oldTextureObject, &oldTextureImage);
  60.                     
  61.                     Q3Object_Dispose(oldTextureObject);
  62.                     Q3TextureShader_SetTexture(firstObject, textureObject);
  63.                     Q3Object_Dispose(textureObject);
  64.                 } else {
  65.                     textureShader = Q3TextureShader_New(textureObject);
  66.                     if( textureShader ) {
  67.                         Q3Object_Dispose(textureObject);
  68.                         Q3Group_SetPositionObject(theGroup, position, textureShader);
  69.                         Q3Object_Dispose(textureShader);
  70.                     } else {
  71.                         return(kQ3Failure);
  72.                     }
  73.                 }
  74.             } else {
  75.                 textureShader = Q3TextureShader_New(textureObject);
  76.                 if( textureShader ) {
  77.                     Q3Object_Dispose(textureObject);
  78.                     Q3Group_AddObject(theGroup, textureShader);
  79.                     Q3Object_Dispose(textureShader);
  80.                 } else {
  81.                     return(kQ3Failure);
  82.                 }
  83.             }
  84.             
  85.         }
  86.         return(kQ3Success);
  87.     } else {
  88.         return(kQ3Failure);
  89.     }
  90. }
  91.  
  92. TQ3Status PictureFileToPixmap( TQ3StoragePixmap *bMap )
  93. {
  94.     TQ3Status        status = kQ3Failure;
  95.     PicHandle         thePicture = nil;
  96.     
  97.     bMap->image = NULL;
  98.     
  99.     thePicture = GetPICTFile();
  100.     if(thePicture != NULL ) {
  101.     
  102.         if (LoadMapPICT( thePicture, 
  103.                      0L,
  104.                      (unsigned long)((**thePicture).picFrame.right  - (**thePicture).picFrame.left),
  105.                      (unsigned long)((**thePicture).picFrame.bottom - (**thePicture).picFrame.top),
  106.                      bMap) != 0) {
  107.  
  108.             status = kQ3Success;
  109.         }
  110.     }
  111.  
  112.     return status;
  113. }
  114.  
  115. TQ3Status TextureGroup( TQ3GroupObject    theGroup)
  116. {
  117.     TQ3Status            status = kQ3Failure;
  118.     TQ3StoragePixmap     myMap;
  119.     
  120.     if (PictureFileToPixmap(&myMap) == kQ3Success) {
  121.         if( myMap.image != NULL ) {
  122.             status = AddTextureToGroup( theGroup, &myMap ) ;
  123.  
  124.             Q3Object_Dispose(myMap.image);
  125.             myMap.image = NULL;
  126.         }
  127.     }
  128.  
  129.     return status;
  130. }
  131.